package com.order.staff.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.order.staff.domain.OrderStaff;
import com.order.staff.service.IOrderStaffService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 员工管理Controller
 * 
 * @author huhu
 * @date 2020-08-19
 */
@Controller
@RequestMapping("/order/staff")
public class OrderStaffController extends BaseController
{
    private String prefix = "order/staff";

    @Autowired
    private IOrderStaffService orderStaffService;

    @RequiresPermissions("order:staff:view")
    @GetMapping()
    public String staff()
    {
        return prefix + "/staff";
    }

    /**
     * 查询员工管理列表
     */
    @RequiresPermissions("order:staff:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderStaff orderStaff)
    {
        startPage();
        List<OrderStaff> list = orderStaffService.selectOrderStaffList(orderStaff);
        return getDataTable(list);
    }

    /**
     * 导出员工管理列表
     */
    @RequiresPermissions("order:staff:export")
    @Log(title = "员工管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderStaff orderStaff)
    {
        List<OrderStaff> list = orderStaffService.selectOrderStaffList(orderStaff);
        ExcelUtil<OrderStaff> util = new ExcelUtil<OrderStaff>(OrderStaff.class);
        return util.exportExcel(list, "staff");
    }

    /**
     * 新增员工管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存员工管理
     */
    @RequiresPermissions("order:staff:add")
    @Log(title = "员工管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderStaff orderStaff)
    {
        return toAjax(orderStaffService.insertOrderStaff(orderStaff));
    }

    /**
     * 修改员工管理
     */
    @GetMapping("/edit/{staffId}")
    public String edit(@PathVariable("staffId") Long staffId, ModelMap mmap)
    {
        OrderStaff orderStaff = orderStaffService.selectOrderStaffById(staffId);
        mmap.put("orderStaff", orderStaff);
        return prefix + "/edit";
    }

    /**
     * 修改保存员工管理
     */
    @RequiresPermissions("order:staff:edit")
    @Log(title = "员工管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderStaff orderStaff)
    {
        return toAjax(orderStaffService.updateOrderStaff(orderStaff));
    }

    /**
     * 删除员工管理
     */
    @RequiresPermissions("order:staff:remove")
    @Log(title = "员工管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderStaffService.deleteOrderStaffByIds(ids));
    }
}
